package com.yeswater.multithread.chapter7;

/**
 * author : yeswater
 * date : 2023/11/6
 *
 * 递归取得 | 非递归取得 组内对象
 */

public class Run_7_2_7 {
    public static void main(String[] args) {
        ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();
        ThreadGroup groupA = new ThreadGroup(mainGroup, "A");
        ThreadGroup groupB = new ThreadGroup(groupA, "B");

        // 分配空间 但不一定全部用完
        ThreadGroup[] list = new ThreadGroup[Thread.currentThread().getThreadGroup().activeGroupCount()];
        // 传入 true 时,递归取得子组及子孙组
        Thread.currentThread().getThreadGroup().enumerate(list, true);
        for (ThreadGroup threadGroup : list) {
            if (threadGroup != null) {
                System.out.println(threadGroup.getName());
            }
        }

        ThreadGroup[] list2 = new ThreadGroup[Thread.currentThread().getThreadGroup().activeGroupCount()];
        Thread.currentThread().getThreadGroup().enumerate(list2, false);
        for (ThreadGroup threadGroup : list2) {
            if (threadGroup != null) {
                System.out.println(threadGroup.getName());
            }
        }
    }
}
